<template>
  <v-dialog
    :title="title"
    :close-on-click-modal="false"
    v-model="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'" label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="标题" prop="title"
                :rules="[
                 ]">
              <el-input v-model="inputForm.title" placeholder="请填写标题"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24"></el-col>
        <el-col :span="12">
            <el-form-item label="发起人" prop="userName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.userName" placeholder=""     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24"></el-col>

        <el-col :span="12">
            <el-form-item label="发起时间" prop="deliverTime"
                :rules="[
                 ]">
              <el-input v-model="inputForm.deliverTime" placeholder=""     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="22">
            <el-form-item label="内容" prop="content"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.content" placeholder="请填写内容"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="处理结果" prop="status"
                :rules="[
                 ]">
              <el-input v-model="inputForm.status" placeholder="" ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="附件地址" prop="attachment"
                :rules="[
                 ]">
                <!-- <file-upload v-model="inputForm.attachment" :limit="3" tip="最多上传3个文件,单个文件不要超过10M"></file-upload> -->
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <template #footer>
      <div>
        <el-form  label-width="120px">
          <el-col :span="22">
          <el-form-item label="备注" >
              <el-input v-model="inputForm.remarks" placeholder="" ></el-input>
          </el-form-item>
        </el-col>
        </el-form>
      </div>
        
        <span class="dialog-footer">
          <el-button @click="doSubmit('已拒绝')"  icon="circle-close">拒绝</el-button>
          <el-button  type="primary" @click="doSubmit('已同意')" icon="circle-check" v-noMoreClick>同意</el-button>
        </span>
    </template>    
  </v-dialog>
</template>

<script>
  import officeRequestService from '@/api/organization/officeRequestService.js'
  import officeRecordService from '@/api/organization/officeRecordService'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          userName:"",
          approverName: '',
          title: '',
          content: '',
          deliverTime: '',
          status:"",
          attachment: '',
          remarks:""
        },
        recordData:{
          id:"",
          remarks:"",
          status:"",
        },
      }
    },
    components: {
    },
    created () {
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建请示稿件`
        } else if (method === 'edit') {
          this.title = '修改请示稿件'
        } else if (method === 'view') {
          this.title = '查看请示'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            officeRequestService.selectById(this.inputForm.id).then((data) => {
              this.inputForm = this.recover(this.inputForm, data)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit (val) {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.recordData.id=this.inputForm.id
            this.recordData.remarks=this.inputForm.remarks
            this.recordData.status=val
            console.log(this.recordData)
            officeRecordService.save(this.recordData).then((data) => {
              this.visible = false
              this.$message.success(data)
              this.$emit('refreshDataList')
              this.loading = false
            }).catch(() => {
              this.loading = false
            })
          }
        })
      }
    }
  }
</script>

  
